﻿using System.IO;

namespace Z.IconLibraryGenerator.WinForm
{
    public partial class IconLibraryGeneratorManager
    {
        public static void GenerateSupportFile(ProjectConfiguration project)
        {
            DirectoryInfo dir = My.TemplateFile.SupportFile;
            string dirOutput = project.OutputDirectory.PathCombine("SupportFiles");

            foreach (FileInfo file in dir.GetFiles("*.*", SearchOption.AllDirectories))
            {
                string template = file.ReadToEnd();

                template = template.Replace("@(Model.Namespace)", project.ProjectNamespace);
                template = template.Replace("@(Model.HandlerPath)", project.ProjectNamespace + ".axd");

                FileInfo output = file.FullName.Replace(dir.FullName, dirOutput).ToFileInfo();
                output = Path.Combine(output.Directory.FullName, output.GetFileNameWithoutExtension()).ToFileInfo();
                Directory.CreateDirectory(output.Directory.FullName);
                template.SaveAs(output);
            }
        }
    }
}